package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * paas 阶段推进器相关字段 枚举
 *
 * @author shaoxiang.sun
 * @date 2021/11/25 19:22
 * @since v1.0
 */
@Getter
public enum PaasStageEnum {

    //阶段流程ID
    STAGE_PROCESS_ID("long_1", "stageProcessId", FieldTypeEnum.LONG.getType(), "enum.paasStage.attrName.stage_process_id"),

    //阶段ID
    STAGE_ID("long_2", "stageId", FieldTypeEnum.LONG.getType(), "enum.paasStage.attrName.stage_id"),

    //阶段比例
    STAGE_RATIO("long_3", "stageRatio", FieldTypeEnum.STAGE_RATIO.getType(), "enum.paasStage.attrName.stage_radio"),
    ;

    /**
     * 属性
     */
    private String attr;
    /**
     * saasAttr
     */
    private String saasAttr;
    /**
     * 字段类型
     */
    private Integer type;
    /**
     * 属性名称
     */
    private String attrName;

    PaasStageEnum(String attr, String saasAttr, Integer type, String attrName) {
        this.attr = attr;
        this.saasAttr = saasAttr;
        this.type = type;
        this.attrName = attrName;
    }

    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getStageCodeAttr(Integer businessType) {
        if (Objects.equals(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), businessType)) {
            return CustomerManagementEnum.CUSTOMER_STAGE.getAttr();
        } else if (Objects.equals(XbbRefTypeEnum.CLUE.getCode(), businessType)) {
            return ClueEnum.CLUE_STAGE.getAttr();
        } else if (Objects.equals(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), businessType)) {
            return SalesOpportunityEnum.SALE_STAGE.getAttr();
        }
        return null;
    }
}
